<!--学位考试管理-->
<template>
  <div class="courseBox">
    <div class="top">
        <el-card>
            <el-form :inline="true" :model="formSearch" class="demo-form-inline">
                <el-form-item label="姓名：">
                    <el-input v-model="formSearch.name" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="班级：">
                    <el-input v-model="formSearch.clbum" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="年级：">
                    <el-input v-model="formSearch.grade" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="searchTop">查询</el-button>
                    <el-button type="info" @click="reset" size="small">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
    <div class="bottom">
        <el-card>
            <el-button type="primary" size="small" @click="exportBtn">导出</el-button>
            <el-table :data="tableData" border style="width: 100%">
                <el-table-column type="index" label="序号" width="80"></el-table-column>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="sex" label="性别">
                    <template slot-scope="scope">
                        <span>{{scope.row.sex == '40' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="school" label="学校"></el-table-column>
                <el-table-column prop="grade" label="年级"></el-table-column>
                <el-table-column prop="clbum" label="班级"></el-table-column>
                <el-table-column prop="degree" label="报名学位"></el-table-column>
                <el-table-column prop="examinationTime" label="考试时间"></el-table-column>
                 <el-table-column
                    fixed="right"
                    label="操作">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="release(scope.row)">详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
             <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryParams.pageNum"
                :page-sizes="[5,10,15,20,25]"
                :page-size="queryParams.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-card>
    </div>
    <!-- 新增-->
   <div class="dialog">
        <el-dialog
            title="详情"
            :visible.sync="dialogVisible"
            width="30%"
            :before-close="handleClose">
            <el-form ref="ruleForm" :label-position="labelPosition" :model="ruleForm" label-width="80px">
              <div class="detail">
                <el-form-item label="姓名：">
                  <el-input v-model="ruleForm.name" disabled></el-input>
                </el-form-item>
                <el-form-item label="性别：">
                  <el-input v-model="ruleForm.sex" disabled></el-input>
                </el-form-item>
                <el-form-item label="学校：">
                  <el-input v-model="ruleForm.school" disabled></el-input>
                </el-form-item>
                <el-form-item label="年级：">
                  <el-input v-model="ruleForm.grade" disabled></el-input>
                </el-form-item>
                <el-form-item label="班级：">
                  <el-input v-model="ruleForm.clbum" disabled></el-input>
                </el-form-item>
                <el-form-item label="报名学位：">
                  <el-input v-model="ruleForm.degree" disabled></el-input>
                </el-form-item>
                <el-form-item label="考试时间：">
                  <el-input v-model="ruleForm.examinationTime" disabled></el-input>
                </el-form-item>
              </div>
            </el-form>
            <div class="footerBtn">
              <el-button type="primary" size="small" @click="cancel">取消</el-button>
            </div>
        </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  getExamineemanageListApi,
  ExportExamineemanageListApi
} from "@/api/degree/examineemanage.js"
export default {
  data() {
    return {
      formSearch: {},
      ruleForm: {},
      labelPosition: "left",
      dialogVisible: false,
      dialogVisible2: false,
      form2: {},
      tableData: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      currentPage:1,
      filename:'考生管理'
    };
  },

  mounted() {
    this.getExamineemanageList()
  },

  methods: {
    // 列表
    getExamineemanageList(obj) {
      getExamineemanageListApi({...obj,pageSize:'10',pageNum:this.currentPage}).then(res=>{
        if(res.code === 200) {
          this.tableData = res.rows
          this.total = res.total
        }
      })
    },

    // 搜索
    searchTop() {
      this.getExamineemanageList(this.formSearch)
    },

    // 导出
    exportBtn() {
        this.$confirm("是否导出全部数据？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
              ExportExamineemanageListApi().then((res)=>{
                console.log(res)
                if (!res) return;
                const blob = new Blob([res], {
                  type: "application/vnd.ms-excel",
                }); // 构造一个blob对象来处理数据，并设置文件类型
                if (window.navigator.msSaveOrOpenBlob) {
                  //兼容IE10
                  navigator.msSaveBlob(blob, this.filename);
                } else {
                  const href = URL.createObjectURL(blob); //创建新的URL表示指定的blob对象
                  const a = document.createElement("a"); //创建a标签
                  a.style.display = "none";
                  a.href = href; // 指定下载链接
                  a.download = this.filename; //指定下载文件名
                  console.log(this.filename);
                  a.click(); //触发下载
                  URL.revokeObjectURL(a.href); //释放URL对象
                }
              })
              // const a = document.createElement("a"); //创建a标签
              // a.href = `${HOST}/common/download?fileName=${res.msg}`; // 指定下载链接
              // a.click(); //触发下载
          })
          .catch(() => {});
    },
    handleClose(done) {
      done();
    },

    reset() {
      this.formSearch = {};
      this.getExamineemanageList()
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },

    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },

    // 详情
    release(row) {
      console.log(row);
      this.dialogVisible = true
      this.ruleForm = row
      this.ruleForm.sex = this.ruleForm.sex == '40' ? '男' : '女'
      console.log(this.ruleForm);
    },
    cancel() {
      this.dialogVisible = false
    }
  }
};
</script>

<style lang="scss" scoped>
.courseBox {
  width: 100%;
  padding: 10px;
  .top {
    width: 100%;
    margin-bottom: 10px;
  }
  .dialog {
    .block {
      width: 280px;
      height: 30px;
      border: solid 1px #dcdfe6;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      box-sizing: border-box;
      background-color: #fff;

      ::v-deep .el-input__inner {
        width: 240px;
        height: 28px;
        border: none;
      }

      ::v-deep .el-icon-arrow-down {
        color: #c2c2c2;
        padding: 0 10px 0 0;
      }

      ::v-deep .el-icon-arrow-up {
        color: #c2c2c2;
        padding: 0 10px 0 0;
      }

      ::v-deep .el-date-picker.has-sidebar {
        left: 460px !important;
        background-color: #4895db;
      }
    }

    .mb,
    .px {
      ::v-deep .el-form-item__content {
        display: flex;
        width: 280px;
        line-height: 30px;
        border: solid 1px #dcdfe6;
        box-sizing: border-box;
        background-color: #fff;
        border-radius: 5px;

        .el-input__inner {
          border: none;
        }

        span {
          font-size: 14px;
          padding-left: 5px;
          color: #888;
        }
      }
    }

    ::v-deep .el-dialog {
      max-width: 750px;
      min-width: 500px;
      border-radius: 10px;
      background-color: #f9f9f9;
    }

    ::v-deep .el-dialog__header {
      height: 48px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 18px;
      background-color: #4895db;
      padding: 0;
      border-radius: 10px 10px 0 0;

      span {
        font-size: 16px;
        color: #fff;
      }
    }

    ::v-deep .el-select > .el-input {
      display: block;
      width: 300px;
    }

    ::v-deep .el-form-item__label {
      line-height: 32px;
      text-align: right;
      width: 84px !important;
    }

    ::v-deep .el-input__inner {
      height: 30px;
      line-height: 30px;
    }

    ::v-deep .el-dialog__headerbtn {
      top: 15px;
    }

    ::v-deep .el-dialog__headerbtn .el-dialog__close {
      color: #fff;
      font-size: 18px;
    }

    ::v-deep  .el-dialog__body {
      text-align: initial;
      display: flex;
      justify-content: center;
      flex-direction: column;
      align-items: center;
    }

    ::v-deep .el-input__icon {
      line-height: 30px;
    }

    ::v-deep .el-form-item__content {
      width: 300px;
      line-height: 30px;
      margin-left: 0 !important;
    }

    ::v-deep .el-form-item {
      margin-bottom: 15px;
      display: flex;
      justify-content: center;
    }

    ::v-deep .el-dialog__footer {
      padding: 10px 20px 40px;
    }

    // ::v-deep .el-button + .el-button {
    //   border-radius: 20px;
    //   margin-left: 50px;
    //   background-color: #4895db;
    //   border-color: #4895db;
    // }
  }
}
</style>